﻿using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using Exhibition.Dao;

using Exhibition.Service;

using Exhibition.Common.Helper;

using Exhibition.Dao.ViewModel;

namespace Exhibition.manager
{

    public partial class FloorDetail : BaseAdminPage
    {

        FloorModel model = new FloorModel();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                hfId.Value = reqID.ToString();
                BindPav();
                GetFloor();
            }

        }

        private void BindPav()
        {
            List<PavilionModel> mdls = CenterService.pavilionService.GetPavilionList(CurrentSite.Id);
            StringUtils.BindDropdownList(drpPav, "PaName","Id",mdls);
            drpPav.Items.Insert(0,new ListItem("请选择展馆","0"));
        }

        private void GetFloor()
        {

            model = CenterService.floorService.GetOneById(reqID);
            if (model != null)
            {

                //楼层名称
                txtFloorName.Value = model.FloorName;
                drpPav.SelectedValue = model.PID.ToString();
                //展馆ID


               // txtPID.Value = model.PID.ToString();

                //楼层图片
                // txtFloorPath.Value= model.FloorPath.ToString();
                if (!string.IsNullOrEmpty(model.FloorPath)) {
                    spPic.InnerHtml = string.Format("<img src='{0}' width='160' height='120'/>", model.FloorPath);
                }
                //排序
                txtOrderID.Value = model.OrderID.ToString();



            }

        }

        /// <summary>
        /// 保存一条数据
        /// <summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {

            model = string.IsNullOrEmpty(hfId.Value)||hfId.Value=="0" ? new FloorModel() : CenterService.floorService.GetOneById(Convert.ToInt32(hfId.Value));
            //楼层名称
            model.FloorName = txtFloorName.Value;

            //展馆ID
            model.PID = Convert.ToInt32(drpPav.SelectedValue );

            //楼层图片
            

            //排序
            model.OrderID = Convert.ToInt32(txtOrderID.Value);

            //SiteID
            model.SiteID= CurrentSite.Id;
            model.CreateUserId = model.CreateUserId == 0 ? AdminUser.Id : model.CreateUserId;
            //
            // model.CreateUserId= Convert.ToInt32(txtCreateUserId.Value);

            if (CenterService.floorService.Save(model) > 0)
            {

                JsHelper.Unblock(this, CommFunMsg.GetMessage("A0001", Lan.zh));
            }
            else
            {
                JsHelper.Unblock(this, CommFunMsg.GetMessage("e0001", Lan.zh));
            }
        }

    }

}

